package org.grayrabbit.cms.content.base;

import java.io.File;
import java.util.TimerTask;

import org.grayrabbit.cms.util.FilePathSptUtil;
import org.grayrabbit.cms.util.FileUtil;


/**
 *		ExportFileTask.java
 *		@Author      hasau   
 *		@CreateTime  2012-2-13  下午5:35:02	
 **/
public class ExportFileTask extends TimerTask {
	
	/** 每2小时 运行一次*/
	public static final  long TIME_SPACE = 2*60*60*1000;
	
	/**系统启动后  1 小时 开始运行*/
	public static final  long TIME_DELAY = 1*60*60*1000;
	
	
	@Override
	public void run() {
		String path = FilePathSptUtil.UPLOAD_ROOT_PATH+Common.SPT+Common.CONTENT; 
		File file = new File (path);
		if(file.exists() && file.isDirectory()){
			File[] files = file.listFiles();
			long l = 0;
			long now = 0;
			for(File f: files){
				l =  f.lastModified();
				now = System.currentTimeMillis();
				long space = now - l ;
				if(space > TIME_SPACE){
					if(f.isFile()){
						f.delete();
					}else{
						FileUtil.delFolder(f.getAbsolutePath());
					}
				}  
			}
			l = 0;
			now = 0; 
		}		
	} 
}
